package com.lei.study.mvel.basic;

import org.junit.Before;
import org.junit.Test;
import org.mvel2.MVEL;

import java.util.HashMap;
import java.util.Map;

/**
 * mvel-基础语法-属性表达式
 *
 * @author 伍磊
 */
public class AttributeExpression {

    private Map<String, Object> map = new HashMap<>(16);

    @Before
    public void init() {
        map.put("user", new User("伍磊", 25));
    }

    @Test
    public void get() {
        // 通过eval表达式获取
        System.out.println(MVEL.eval("user.age", map));

        MVEL.eval("user.age = 30", map);

        System.out.println(MVEL.eval("user.age", map));

        MVEL.eval("with(user){name='伍磊测试', age=1}", map);

        System.out.println(MVEL.eval("user", map));
    }
}
